package com.caiyi.financial.nirvana.sms.gateway;

import com.alibaba.fastjson.JSON;
import com.caiyi.financial.nirvana.sms.queue.SendQueueEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SendTask implements Runnable {

    private static final Logger logger = LoggerFactory.getLogger(SendTask.class);

    private String messageInfo;
    private DefaultGateWay gateWay;

    public SendTask(String messageInfo, DefaultGateWay gateWay) {
        this.messageInfo = messageInfo;
        this.gateWay = gateWay;
    }

    @Override
    public void run() {
        try {
            SendQueueEntity entity = JSON.parseObject(messageInfo, SendQueueEntity.class);
            // 通过网关发送消息
            gateWay.sendMessage(entity);
        } catch (Exception e) {
            logger.error("SendTask run error ! ", e);
        }
    }

}
